package com.hdjk.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.liangmutian.mypicker.DateUtil;
import com.hdjk.view.R;
import com.hdjk.view.entity.SellResult;

import java.util.List;

import static com.hdjk.view.R.id.tv_name;
import static com.hdjk.view.R.id.tv_text1;

/**
 * Created by sxy on 2017/11/3.
 */

public class RedeemSuccessAdapter extends BaseAdapter {
    private List<SellResult> mList;
    private Context mContext;

    public RedeemSuccessAdapter(Context context) {
        mContext = context;
    }

    public void setDataList(List<SellResult> list) {
        mList = list;
    }

    @Override
    public int getCount() {
        return mList != null ? mList.size() : 0;
    }

    @Override
    public SellResult getItem(int position) {
        return mList != null ? mList.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_redeem_success, null);
            holder.tv_name = (TextView) convertView.findViewById(tv_name);
            holder.tv_text1 = (TextView) convertView.findViewById(tv_text1);
            holder.tv_text2 = (TextView) convertView.findViewById(R.id.tv_text2);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        SellResult entity = mList.get(position);
        holder.tv_name.setText(entity.getFundName());
        if (entity.getTransactionStatus() != null || !entity.getTransactionStatus().equals("")) {
            if (entity.getTransactionStatus().equals("received")) {
                holder.tv_text1.setText("下单时间：" + DateUtil.formatDate(Long.parseLong(entity.getOrderDate()), "yyyy-MM-dd"));
                holder.tv_text2.setText("预计到账时间：" + DateUtil.formatDate(Long.parseLong(entity.getExpectedDealDate()), "yyyy-MM-dd"));

                holder.tv_name.setTextColor(mContext.getResources().getColor(R.color.text_black_202020));
                holder.tv_text1.setTextColor(mContext.getResources().getColor(R.color.black_666666));
                holder.tv_text2.setTextColor(mContext.getResources().getColor(R.color.black_666666));
            } else {
                holder.tv_text1.setText("赎回失败");
                holder.tv_text2.setText(entity.getReason() != null ? entity.getReason() : "");

                holder.tv_name.setTextColor(mContext.getResources().getColor(R.color.bg_common_red));
                holder.tv_text1.setTextColor(mContext.getResources().getColor(R.color.bg_common_red));
                holder.tv_text2.setTextColor(mContext.getResources().getColor(R.color.bg_common_red));
            }
        }

        return convertView;
    }

    class Holder {
        TextView tv_name;
        TextView tv_text1;
        TextView tv_text2;
    }
}
